Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

276
Visualizações
How can I show "empty" if data is not there?

Because of this

<v-card-subtitle class="py-0 my-0">{{ vc_rule.url }}</v-card-subtitle>

where this.vc_rule could be empty or null. Sometimes, I got this error on my console.

vue.runtime.esm.js?2b0e:1897 TypeError: Cannot read properties of undefined (reading 'url')

Instead of getting this error, how can I tell Vue.js to show "empty" if data is not there?

I envision something like this :

Hint: ?

<v-card-subtitle class="py-0 my-0">{{ vc_rule?.url }}</v-card-subtitle>
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You can combine the optional chaining operator with the nullish coalescing operator like this :

<v-card-subtitle class="py-0 my-0">{{ vc_rule?.url ?? 'empty' }}</v-card-subtitle>
about 4 years ago · Juan Pablo Isaza Relatório

0

If I understand your requirement correctly, we can achieve that in the HTML template itself via use of Optional chaining (?.) along with Nullish coalescing operator (??).

Working Demo :

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data() {
    return {
      vc_rule: null
    }
  }
})
<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"></script>
<link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet">

<div id="app">
  <v-card-subtitle class="py-0 my-0">{{ vc_rule?.url ?? 'empty' }}</v-card-subtitle>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

Try with Logical_OR -> ||

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data() {
    return {
      vc_rule: null
    }
  }
})
<link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet">

<div id="app">
  <v-app>
    <v-card>
      <v-card-subtitle class="py-0 my-0">{{ vc_rule?.url || 'empty' }}</v-card-subtitle>
    </v-card>
  </v-app>
</div>

<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"></script>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda